import Vue from "vue";
import VueI18n from "vue-i18n";
import en from "@/locales/en.json";
import zh from "@/locales/zh-CN.json";
import ru from "@/locales/ru.json";
import kz from "@/locales/kk.json";
import enLocale from "element-ui/lib/locale/lang/en";
import zhLocale from "element-ui/lib/locale/lang/zh-CN";
import ruRULocale from "element-ui/lib/locale/lang/ru-RU";
import kzLocale from "element-ui/lib/locale/lang/kz";
import ElementLocale from "element-ui/lib/locale";
Vue.use(VueI18n);
export default ({ app, store }) => {
  // Set i18n instance on app
  // This way we can use it in middleware and pages asyncData/fetch
  app.i18n = new VueI18n({
    locale: app.$cookies.get("locale") ? app.$cookies.get("locale") : "zh-CN",
    fallbackLocale: "zh-CN",
    messages: {
      en: { ...en, ...enLocale },
      "zh-CN": { ...zh, ...zhLocale },
      ru: { ...ru, ...ruRULocale },
      kz: { ...kz, ...kzLocale },
    },
  });
  ElementLocale.i18n((key, value) => app.i18n.t(key, value));
  app.i18n.path = (link) => {
    if (app.i18n.locale === app.i18n.fallbackLocale) {
      return `/${link}`;
    }
    return `/${app.i18n.locale}/${link}`;
  };
};
